//
//  XGHomeStatusViewModel.swift
//  WeIBo
//
//  Created by 苏文潇 on 2017/3/12.
//  Copyright © 2017年 苏文潇. All rights reserved.
//

import UIKit

class XGHomeStatusViewModel: NSObject {

    lazy var statusList:[XGStatusViewModel] = [XGStatusViewModel]()
    
    func loadData(callBack: @escaping (Bool)->()){
        
        XGAFNetworkingTools.sharedTools.statusMessage { (response, error) in
            if error != nil {
                print(error!)
                return
            }
            
            let dic = response as! [String: Any]
            
            let dataArray = dic["statuses"] as! [[String: Any]]
            
            //            var arrarList = [XGStatusModel]()
            //            for arrayDic in dataArray
            //            {
            ////                 字典转模型
            ////                let status = XGStatusModel(dic: arrayDic)
            //
            //                arrarList.append(status)
            //            }
            
            let status = NSArray.yy_modelArray(with: XGStatusModel.self, json: dataArray) as! [XGStatusModel]
         
            var tempArray = [XGStatusViewModel]()
            
            for dataModel in status
            {
                let viewModel = XGStatusViewModel()
                
                viewModel.status = dataModel
                
                tempArray.append(viewModel)
            }
           //            将数据存入到全局数组保存
            self.statusList = tempArray
            
            callBack(true)
            
        }
        
    }
    
}
